package busca.tesoros.uclm;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.app.ListActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class SelMisionActivity extends ListActivity 
{
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		
		SQLiteDatabase myDB = this.openOrCreateDatabase("BDTesoros.s3db", 1, null);
		//BORRAR solo para pruebas
		
		Cursor c = myDB.rawQuery("SELECT * FROM Misiones", null);
		startManagingCursor(c);
		
		ListAdapter adapter = new SimpleCursorAdapter(this,
				R.layout.database_item,c,
				new String []{"MISIONES._id","MISIONES.Nombre", "MISIONES.estado"},
				new int [] {R.id.textView_id, R.id.textView_titulo, R.id.textView_estado});
		
		setListAdapter(adapter);
		getListView().setTextFilterEnabled(true);
		myDB.close();
		  
    }

	protected void onListItemClick(ListView l, View v, int position, long id)
	{
		Log.i(getPackageName(), "Seleccionado Mision: " + id);
		//Toast.makeText(this, "Pulsando item " + position+ " " +id, Toast.LENGTH_LONG).show();
		Intent i = new Intent(this, BienvenidoActivity.class);
		i.putExtra("mision", id);
		startActivity(i);		 
	}
	

}


